package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.ClothginQuiryBean;
import com.ukao.cashregister.bean.ReadBean;
import com.ukao.cashregister.bean.UserInfoBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.ThreadUtils;
import com.ukao.cashregister.utils.Utils;
import com.ukao.cashregister.view.CreateOrdersView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class CreateOrdersPesenter  extends BasePresenter<CreateOrdersView> {

    public CreateOrdersPesenter(CreateOrdersView view) {
        attachView(view);
    }




    /**
     *获取用户信息
     */
    public void placeOrderData(Context  context,final String searchValue   ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("key",searchValue);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.placeOrder(Constant.createParameter(mHashMap)),
                new ApiCallback<UserInfoBean>() {
                    @Override
                    public void onSuccess(UserInfoBean model) {
                        mvpView.hideLoading();
                        if (model.getHttpCode()==200){
                            mvpView.loadOrderSuccess(model,searchValue);
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }
    /**
     *获取衣物订单信息
     */
    public void clothginQuirydetail(Context  context,final  String searchValue   ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("scanCode",searchValue);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.clothginQuirydetail(Constant.createParameter(mHashMap)),
                new ApiCallback<ClothginQuiryBean>() {
                    @Override
                    public void onSuccess(ClothginQuiryBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.loadClothingSuccess(model.getData(),searchValue);
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }
    /**
     * 取衣
     */
    public void takeUserClothing(Context  context,final  String searchValue   ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("searchValue",searchValue);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.takeUserClothing(Constant.createParameter(mHashMap)),
                new ApiCallback<UserInfoBean>() {
                    @Override
                    public void onSuccess(UserInfoBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.loadOrderSuccess(model,  searchValue);
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }

                });
    }

    /**
     *RFID
     */
    public void rfidSecret(final String rfidSecret   ) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mvpView.showLoading();
                HashMap     mHashMap=new HashMap<String,String>();
                mHashMap.put("rfidSecret",rfidSecret);
                mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
                addSubscription(apiStores.rfidSecret(Constant.createParameter(mHashMap)),
                        new ApiCallback<ReadBean>() {
                            @Override
                            public void onSuccess(ReadBean model) {

                                if (model.getHttpCode()==200){
                                    mvpView.loadRfrdSuccess(model);
                                }else{
                                    mvpView.loadFail(model.getMsg());
                                }
                            }
                            @Override
                            public void onFinish() {
                                mvpView.hideLoading();
                            }

                        });
            }
        });

    }


}
